package com.xbongbong.paas.handle;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.weblist.pojo.ListOptionPackagePojo;
import com.xbongbong.saas.enums.ListGroupEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.help.SaasListHelp;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 客户操作方式
 * @author 吴峰
 * @version v1.0
 * @date 2020/3/27 11:23
 * @since v1.0
 */
@Component
public class ContractOptionHandle extends AbstractOptionHandle {

    @Resource
    private SaasListHelp saasListHelp;

    @Override
    public void setOptionsInExplain(FormDataListDTO formDataListDTO, List<FieldAttrEntity> explainList, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        String corpid = formDataListDTO.getCorpid();
        // 获取按钮的开关
        ListOptionPackagePojo listOptionPackagePojo = getListOption(formDataListDTO);

        // 拼装表头
        saasListHelp.setHeadList(explainList, listOptionPackagePojo, formDataListDTO.getSubBusinessType(),formDataListDTO.getBusinessType());
        // 去掉子表单标题头，实际上可以加在HandleExplainHelp.handleExplain中，但是避免对其他业务造成影响，先写在这里，如果全部列表改造的话，可统一改到HandleExplainHelp.handleExplain中
        removeSubFormItems(explainList, formDataListDTO.getBusinessType());
    }

    @Override
    public ListOptionPackagePojo getFirstOptionData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        // ‘归’标签
        ListOptionPackagePojo listOptionPackagePojo = new ListOptionPackagePojo();
        listOptionPackagePojo.setArchivedTag(ContractEnum.CONTRACT_NO.getAttr() + "Tag");
        return listOptionPackagePojo;
    }

    private ListOptionPackagePojo getListOption(FormDataListDTO formDataListDTO) throws XbbException {
        ListOptionPackagePojo listOptionPackagePojo = new ListOptionPackagePojo();
        if (Objects.equals(1, formDataListDTO.getDefaultGroup()) && Objects.equals(formDataListDTO.getListGroupId(), Long.valueOf(ListGroupEnum.APPROVAL.getCode()))) {
            return listOptionPackagePojo;
        }
        //提醒
        listOptionPackagePojo.setNeedOption2(true);
        saasListHelp.getPushNotify(formDataListDTO.getIdIn(), formDataListDTO.getCorpid(), formDataListDTO.getBusinessType(), listOptionPackagePojo.getPushNotifyList());

        return listOptionPackagePojo;
    }

    @Override
    public void setOptionsInData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        setOptions(formDataListDTO, paasFormDataEsListVO, getListOption(formDataListDTO));
    }
}
